package data 
{
	import ui.popup.GCTextPopup;
	import flash.utils.Dictionary;
	/**
	 * ...
	 * @author Roy
	 */
	public class GCExperienceData 
	{
		/*
		 * Message to display when a player levels up
		 */
		public static const EXP_FIRST_LEVEL_UP:String = "Congratulations you have earned enough XP to gain a fame level! Due to you increased reputation, " +
			"you have gained access to a ship you can use to travel and transport goods to other places.";
		
		public static const EXP_SECOND_LEVEL_UP:String = "You have gained another fame level! You have gained the attention of more customers, you can expect to " +
			"to have more orders. In addition, you have been rewarded with a batch of new goods in your warehouse in Picaroon."
		
		public static const EXP_THIRD_LEVEL_UP:String = "Your fame continues to grow! As a result of your hard work you have unlocked the ability to construct " +
			"buildings that produce goods. Three workers have also joined your crew, they can help gather resources.";
		
		public static const EXP_GENERAL_LEVEL_UP:String = "Congratulations, you have gained a fame level.\n\n" +
			"As a reward, an extra worker has been placed on your ship. You can use the worker to gather more resources!";
		
		/*
		 * This list will map out how much experience is need for a player to reach
		 * the next fame level.
		 */
		public static var _experienceSequence:Vector.<uint>;
		
		/*
		 * Total experience required to be at a level (index is the level, value is total xp to reach that level)
		 */
		public static var _totalExperienceNeeded:Vector.<uint>;
		
		public static function init():void
		{
			_experienceSequence = new Vector.<uint>(100);
			_totalExperienceNeeded = new Vector.<uint>(100);
			var i:uint;
			_experienceSequence[0] = 0;
			_experienceSequence[1] = 100;
			
			_totalExperienceNeeded[1] = 0;
			
			var modifier:Number = 2;
			if (i > 6)
			{
				modifier = 1.5;
			}
			if (i > 20)
			{
				modifier = 1.25;
			}
			if (i > 40)
			{
				modifier = 1.0;
			}
			
			for (i = 2; i < 100; i++)
			{
				_experienceSequence[i] = 2 * _experienceSequence[i - 1];
				_totalExperienceNeeded[i] = _totalExperienceNeeded[i - 1] + _experienceSequence[i - 1];
			}
		}
		
		/**
		 * Get the player level depending on the total experience they have.
		 * 
		 * @param	totalXP
		 * @return
		 */
		public static function getLevelFromXP(totalXP:uint):uint
		{
			var i:uint;
			for (i = 1; i < _totalExperienceNeeded.length; i++)
			{
				if (_totalExperienceNeeded[i + 1] > totalXP)
				{
					return i;
				}
			}
			
			// level 99
			return _totalExperienceNeeded.length;
		}
		
		public static function giveExperienceReward():void
		{
			if (GCPlayState.playerData.playerLevel == 8)
			{
				var shipReward1:Dictionary = new Dictionary();
				shipReward1[GCItemData.ITEM_SHIP_RECIPE_GALLEY] = 1;
				GCPlayState.rewardPlayerItems(GCCityData.CITY_SHIP, shipReward1);
				GCPlayState.disableScreen(new GCTextPopup("Congratulation you have been awarded a new ship recipe! Use it to build a Galley.", GCPlayState.enableScreen));
			}
			else if (GCPlayState.playerData.playerLevel == 15)
			{
				var shipReward2:Dictionary = new Dictionary();
				shipReward2[GCItemData.ITEM_SHIP_RECIPE_BARGE] = 1;
				GCPlayState.rewardPlayerItems(GCCityData.CITY_SHIP, shipReward2);
				GCPlayState.disableScreen(new GCTextPopup("Congratulation you have been awarded a new ship recipe! Use it to build a Barge.", GCPlayState.enableScreen));
			}
			else if (GCPlayState.playerData.playerLevel == 25)
			{
				var shipReward3:Dictionary = new Dictionary();
				shipReward3[GCItemData.ITEM_SHIP_RECIPE_STEAMBOAT] = 1;
				GCPlayState.rewardPlayerItems(GCCityData.CITY_SHIP, shipReward3);
				GCPlayState.disableScreen(new GCTextPopup("Congratulation you have been awarded a new ship recipe! Use it to build a Steamboat.", GCPlayState.enableScreen));
			}
			else if (Math.random() < 0.4 )
			{
				var recipeReward:Dictionary = new Dictionary();
				var recipeId:uint = (Math.random() * 22) + 501;
				recipeReward[recipeId] = 1;
				GCPlayState.rewardPlayerItems(GCCityData.CITY_SHIP, recipeReward);
				GCPlayState.disableScreen(new GCTextPopup("Congratulation you have been awarded a new recipe!", GCPlayState.enableScreen));
			}
		}
	}

}